# check whether a position is in a box.
# @param { [int, int, int] } from (storage minecraft:rmr arguments.box0_start)
# @param { [int, int, int] } from (storage minecraft:rmr arguments.box0_end)
# @param { [int, int, int] } from (storage minecraft:rmr arguments.box1_start)
# @param { [int, int, int] } from (storage minecraft:rmr arguments.box1_end)
# @returns { bool }

scoreboard objectives add rmr.local.left dummy
scoreboard objectives add rmr.local.right dummy

scoreboard objectives add rmr.local.box0_start_x dummy
scoreboard objectives add rmr.local.box0_start_y dummy
scoreboard objectives add rmr.local.box0_start_z dummy

scoreboard objectives add rmr.local.box0_end_x dummy
scoreboard objectives add rmr.local.box0_end_y dummy
scoreboard objectives add rmr.local.box0_end_z dummy

scoreboard objectives add rmr.local.box1_start_x dummy
scoreboard objectives add rmr.local.box1_start_y dummy
scoreboard objectives add rmr.local.box1_start_z dummy

scoreboard objectives add rmr.local.box1_end_x dummy
scoreboard objectives add rmr.local.box1_end_y dummy
scoreboard objectives add rmr.local.box1_end_z dummy

# box 0
execute store result score @s rmr.local.left run data get storage minecraft:rmr arguments.box0_start[0] 1000
execute store result score @s rmr.local.right run data get storage minecraft:rmr arguments.box0_end[0] 1000
execute if score @s rmr.local.left <= @s rmr.local.right store result score @s rmr.local.box0_start_x run scoreboard players get @s rmr.local.left
execute if score @s rmr.local.left <= @s rmr.local.right store result score @s rmr.local.box0_end_x run scoreboard players get @s rmr.local.right
execute if score @s rmr.local.left > @s rmr.local.right store result score @s rmr.local.box0_start_x run scoreboard players get @s rmr.local.right
execute if score @s rmr.local.left > @s rmr.local.right store result score @s rmr.local.box0_end_x run scoreboard players get @s rmr.local.left

execute store result score @s rmr.local.left run data get storage minecraft:rmr arguments.box0_start[1] 1000
execute store result score @s rmr.local.right run data get storage minecraft:rmr arguments.box0_end[1] 1000
execute if score @s rmr.local.left <= @s rmr.local.right store result score @s rmr.local.box0_start_y run scoreboard players get @s rmr.local.left
execute if score @s rmr.local.left <= @s rmr.local.right store result score @s rmr.local.box0_end_y run scoreboard players get @s rmr.local.right
execute if score @s rmr.local.left > @s rmr.local.right store result score @s rmr.local.box0_start_y run scoreboard players get @s rmr.local.right
execute if score @s rmr.local.left > @s rmr.local.right store result score @s rmr.local.box0_end_y run scoreboard players get @s rmr.local.left

execute store result score @s rmr.local.left run data get storage minecraft:rmr arguments.box0_start[2] 1000
execute store result score @s rmr.local.right run data get storage minecraft:rmr arguments.box0_end[2] 1000
execute if score @s rmr.local.left <= @s rmr.local.right store result score @s rmr.local.box0_start_z run scoreboard players get @s rmr.local.left
execute if score @s rmr.local.left <= @s rmr.local.right store result score @s rmr.local.box0_end_z run scoreboard players get @s rmr.local.right
execute if score @s rmr.local.left > @s rmr.local.right store result score @s rmr.local.box0_start_z run scoreboard players get @s rmr.local.right
execute if score @s rmr.local.left > @s rmr.local.right store result score @s rmr.local.box0_end_z run scoreboard players get @s rmr.local.left
#end

#box 1
execute store result score @s rmr.local.left run data get storage minecraft:rmr arguments.box1_start[0] 1000
execute store result score @s rmr.local.right run data get storage minecraft:rmr arguments.box1_end[0] 1000
execute if score @s rmr.local.left <= @s rmr.local.right store result score @s rmr.local.box1_start_x run scoreboard players get @s rmr.local.left
execute if score @s rmr.local.left <= @s rmr.local.right store result score @s rmr.local.box1_end_x run scoreboard players get @s rmr.local.right
execute if score @s rmr.local.left > @s rmr.local.right store result score @s rmr.local.box1_start_x run scoreboard players get @s rmr.local.right
execute if score @s rmr.local.left > @s rmr.local.right store result score @s rmr.local.box1_end_x run scoreboard players get @s rmr.local.left

execute store result score @s rmr.local.left run data get storage minecraft:rmr arguments.box1_start[1] 1000
execute store result score @s rmr.local.right run data get storage minecraft:rmr arguments.box1_end[1] 1000
execute if score @s rmr.local.left <= @s rmr.local.right store result score @s rmr.local.box1_start_y run scoreboard players get @s rmr.local.left
execute if score @s rmr.local.left <= @s rmr.local.right store result score @s rmr.local.box1_end_y run scoreboard players get @s rmr.local.right
execute if score @s rmr.local.left > @s rmr.local.right store result score @s rmr.local.box1_start_y run scoreboard players get @s rmr.local.right
execute if score @s rmr.local.left > @s rmr.local.right store result score @s rmr.local.box1_end_y run scoreboard players get @s rmr.local.left

execute store result score @s rmr.local.left run data get storage minecraft:rmr arguments.box1_start[2] 1000
execute store result score @s rmr.local.right run data get storage minecraft:rmr arguments.box1_end[2] 1000
execute if score @s rmr.local.left <= @s rmr.local.right store result score @s rmr.local.box1_start_z run scoreboard players get @s rmr.local.left
execute if score @s rmr.local.left <= @s rmr.local.right store result score @s rmr.local.box1_end_z run scoreboard players get @s rmr.local.right
execute if score @s rmr.local.left > @s rmr.local.right store result score @s rmr.local.box1_start_z run scoreboard players get @s rmr.local.right
execute if score @s rmr.local.left > @s rmr.local.right store result score @s rmr.local.box1_end_z run scoreboard players get @s rmr.local.left
#end

scoreboard objectives add rmr.local.x_in dummy
scoreboard objectives add rmr.local.y_in dummy
scoreboard objectives add rmr.local.z_in dummy

execute if score @s rmr.local.box0_end_x >= @s rmr.local.box1_start_x run scoreboard players set @s rmr.local.x_in 1
execute if score @s rmr.local.box0_start_x <= @s rmr.local.box1_end_x run scoreboard players set @s rmr.local.x_in 1

execute if score @s rmr.local.box0_end_y >= @s rmr.local.box1_start_y run scoreboard players set @s rmr.local.y_in 1
execute if score @s rmr.local.box0_start_y <= @s rmr.local.box1_end_y run scoreboard players set @s rmr.local.y_in 1

execute if score @s rmr.local.box0_end_z >= @s rmr.local.box1_start_z run scoreboard players set @s rmr.local.z_in 1
execute if score @s rmr.local.box0_start_z <= @s rmr.local.box1_end_z run scoreboard players set @s rmr.local.z_in 1

execute unless score @s rmr.local.x_in matches 1 run return 0
execute unless score @s rmr.local.y_in matches 1 run return 0
execute unless score @s rmr.local.z_in matches 1 run return 0

return 1